package cn.kgm.makeGodV2.outCome;

import cn.kgm.makeGodV2.GamePlayer;
import cn.kgm.makeGodV2.WorldState;
import cn.kgm.makeGodV2.emotion.PersonalityTrait;

/**
 * 结果处理类:修改人格特征
 *
 * @Version 1.8
 * @Author: Kappi
 * @Date: 2025-9-16 10:35
 * @Description: cn.kgm.makeGodV2.outCome.TraitChangeOutcome
 */
public class TraitChangeOutcome implements EventOutcome {
    private String trait;
    private double change;

    public TraitChangeOutcome(String trait, double change) {
        this.trait = trait;
        this.change = change;
    }

    @Override
    public void apply(GamePlayer npc, WorldState worldState) {
        PersonalityTrait traits = npc.getTraits();
        switch (trait) {
            case "openness":
                traits.setOpenness(clamp(traits.getOpenness() + change));
                break;
            case "conscientiousness":
                traits.setConscientiousness(clamp(traits.getConscientiousness() + change));
                break;
            case "extraversion":
                traits.setExtraversion(clamp(traits.getExtraversion() + change));
                break;
            case "agreeableness":
                traits.setAgreeableness(clamp(traits.getAgreeableness() + change));
                break;
            case "neuroticism":
                traits.setNeuroticism(clamp(traits.getNeuroticism() + change));
                break;
        }
    }

    private double clamp(double value) {
        return Math.max(0, Math.min(100, value));
    }
}
